/**
 * @author Yuliy Khorolinskyy
 *
 * Reaktionsspiel logic
 *
 * 14.12.2011
 */
package control;

import javax.xml.bind.JAXB;

import data.HighScores;
import data.Options;

/**
 * 
 * @author y.khorolinskyy
 * 	<br><br>
 *	Everything concerning reading from or writing on hard drive is handled by this class.
 *	This includes loading and saving options and highscores from or to XML-Files.
 *  <br>
 *  Control over validity or accesability of the XML files is NOT implemented.
 *  
 */
public class IOManager {
	
	/**
	 * Loads the <class>Options</class> class from the XML file from the location specified as loadFile in <class>Options</class>.
	 * @return a new instance of Options which contains data from the file just read.
	 */
	public static Options loadOptions(){
		try {
			return JAXB.unmarshal(Options.getOptionsFile(), Options.class);
		} catch (Exception e) {
			//log
			return new Options();
		}
	}
	
	/**
	 * Saves the <class>Options</class> class to the XML file at the location specified as loadFile in <class>Options</class>.
	 * @param o The Options class to be saved in its XML representation.
	 */
	public static void saveOptions(Options o){
		try {
			JAXB.marshal(o, Options.getOptionsFile());
		} catch (Exception e) {
			//log
		}
	}
	
	/**
	 * Loads the <class>HighScores</class> class from the XML file from the location specified as loadFile in <class>HighScores</class>.
	 * @return a new instance of HighScores which contains data from the file just read.
	 */
	public static HighScores loadHighscores(){
		try {
			return JAXB.unmarshal(HighScores.getHighscoresFile(), HighScores.class);
		} catch (Exception e) {
			// log
			return new HighScores();
		}
	}
	
	/**
	 * Saves the <class>HighScores</class> class to the XML file at the location specified as loadFile in <class>HighScores</class>.
	 * @param hs The HighScore class to be saved in its XML representation.
	 */
	public static void saveHighscores(HighScores hs){
		try {
			JAXB.marshal(hs, HighScores.getHighscoresFile());
		} catch (Exception e) {
			//log
		}
	}

}
